package orm

import (
	"errors"
	"reflect"
)

/**
 * 处理go类型转换
 */

func GetElemPtrFromSlice(s interface{}) (e interface{}, ptr bool, err error) {
	st := reflect.TypeOf(s)
	if st.Kind() == reflect.Ptr {
		ptr = true
		st = st.Elem()
	}
	if st.Kind() != reflect.Slice {
		err = errors.New("必须是数组或指向数组的指针")
		return
	}
	et := st.Elem()
	if et.Kind() == reflect.Ptr {
		e = reflect.New(et.Elem()).Interface()
	} else {
		e = reflect.New(et).Interface()
	}
	return
}